package com.isunland.managesystem.ui;

import android.os.Bundle;
import com.google.gson.Gson;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.ContractContent;
import com.isunland.managesystem.entity.ContractContentOriginal;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.CustomerDialog;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class NewContractDialogFragment extends BaseNetworkDialogFragment {

  private CurrentUser mCurrentUser;

  @Override public void onCreate(Bundle savedInstanceState) {
    mCurrentUser = CurrentUser.newInstance(getActivity());
    super.onCreate(savedInstanceState);
  }

  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<CustomerDialog>();

    ContractContentOriginal contractContentOriginal =
        new Gson().fromJson(arg0, ContractContentOriginal.class);

    List<ContractContent> dataList = contractContentOriginal.getDataList();

    if (dataList == null || dataList.size() == 0) {

      return null;
    }
    for (int i = 0; i < dataList.size(); i++) {

      list.add(new CustomerDialog(dataList.get(i).getCONTRACT_NAME(), dataList.get(i).getID(),
          dataList.get(i).getCONTRACT_KIND(), dataList.get(i).getCONTRACT_CODE()));
    }
    return list;
  }

  @Override public String getUrl() {
    return ApiConst.URL_CONTRACT;
  }

  @Override public HashMap<String, String> getparameters() {

    HashMap<String, String> params = new HashMap<String, String>();
    params.put("curPage", "1");
    params.put("pageSize", "2000");
    params.put("style", "tree");
    params.put("memberCode", mCurrentUser.getMemberCode());
    params.put("columnList", "ID,CONTRACT_NAME,CONTRACT_KIND,CONTRACT_CODE");
    params.put("dataStatus", "checkPass");
    return params;
  }
}
